package com.wuzao.objectTest;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class ObjectTest {
    class Person  {
        private int id;
        private String name;
        private List<String> family;

        public Person() {
        }

        public Person(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public List<String> getFamily() {
            return family;
        }

        public void setFamily(List<String> family) {
            this.family = family;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", family=" + family.toString() +
                    '}';
        }
    }


    /**
     * 浅复制只复制对象的基本数据类型字段和引用类型字段的引用地址，不复制引用对象本身。可以使用 clone 方法来实现。
     */
    @Test
    public void test2() {
    String str = "aaaa-bbbb";
        System.out.println(str.split("-")[0]);
    }

    @Test
    public void test3(){
        Person original = new Person(1, "Alice");
        original.setFamily(Arrays.asList("a", "b", "c"));

        Person test = new Person();
        BeanUtil.copyProperties(original, test);
        System.out.println(test);
        test.setId(2);

        List<Person> people = new ArrayList<>();
        people.add(original);
        people.add(test);

        Person any = people.stream().filter(i -> i.getId() == 1).findAny().orElse(new Person());
        any.setId(3);
        System.out.println(people);

    }

    @Test
    public void test4(){
        List<String> list4 = Arrays.asList("1","3","4");
        String str = String.join("#$", list4);
        str = str + "#$";

        System.out.println(str);
    }

}
